package pipeline;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

import descriptors.IDescriptor;

import modul.AModul;
import modulIOContainer.DefaultImageContainer;

public class Pipeline {

	private static final Logger logger = Logger.getLogger(Pipeline.class);
	
	protected List<AModul> pipelineModuls;
	
	public void start(String pipelineConfig){
		
		// get Modullist
		configuratePipeline();
		
		
		// executePipeline
		this.executePipeline(pipelineModuls);
	}
	
	private void configuratePipeline(){
		
//		try {
//			BeanFactory factory = new ClassPathXmlApplicationContext("pipeline.xml");
//			IDescriptor descr = (IDescriptor)factory.getBean("PatchDescriptor");
//			
//			System.out.println(descr==null);
//			
//		} catch (BeansException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
				
	}
	
	private void executePipeline(List<AModul> pipeline){
		
		List<DefaultImageContainer> pipelineInformation=null;
		
		for(AModul modul: pipeline){
			modul.setInput(pipelineInformation);
			
			//run modul
			modul.process();
			
			pipelineInformation = modul.getOutput();
			//save data
			this.savePipelineInformation(pipelineInformation, "output.txt");
		}
	}
	
	private void savePipelineInformation(List<DefaultImageContainer> info, String outputFile){
		
	}
	
	public List<AModul> getPipelineModuls() {
		return pipelineModuls;
	}

	public void setPipelineModuls(List<AModul> pipelineModuls) {
		this.pipelineModuls = pipelineModuls;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Pipeline p= new Pipeline();
		p.start("pipelineConfig.xml");

	}

}
